package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 12/22/20 10:22 AM
 *
 * https://leetcode-cn.com/problems/move-zeroes/
 */
public class _283_移动零 {

    public void moveZeroes(int[] nums) {

        if (nums == null || nums.length == 0) {

            return;
        }

        /**
         * 使用一个负数来表示 left没有赋值，当left赋值之后，就从left开始进行移动
         */
        int left = -1;

        for (int i = 0; i < nums.length; i++) {

            if (nums[i] == 0) {

                if (left < 0) {

                    left = i;
                }
                continue;
            }

            if (left < 0) {

                continue;
            }

            nums[left++] = nums[i];
            nums[i] = 0;
        }

    }
}
